In this video we are going to create a price weighted stock index containing our six stocks.
So the stocks Amazon Boeing Disney IBM and Microsoft are the so-called constituents of our customized
index.
And actually the weights of the constituents and the index are determined by the stock prices.
So first of all let's have a look at our stocks.
We are still important.
The stocks.
Yes we're.
So these are the first five four hours here and we also still import it.
The normalized prices starting from 100 at the thirty first of December 2000 and 13 and actually creating
a price weighted index is nothing else than having for all constituents an equal amount of stocks in
the index.
So the easiest example is to have exactly one stock per constituent in the index.
And consequently the total price of our index would be at each point in time simply the sum of the constituent
prices.
So let's have a look at an example here.
So this is our first time stamp and here are the stock prices for our six stocks.
And if you put that one stock per constituent into one portfolio on index then the value of the portfolio
of the index is simply the sum of the stock prices here.
And action on a first step you want to calculate the sum for all rows here.
So far the timestamps and we can do the same with the sum method and passing one to the access parameter.
So we are calculating the sum for all rows or along the columns.
So let's say this here and for example here for the very first time stamp the sum of all constituent
prices is eight hundred seventy seven.
Then at the next day I hadn't read 74 and so on and we are actually almost finished.
So this is our price weighted index.
And typically we would normalize the index.
So we want to have at the very first time stamp the value of 100.
So we can simply select here the very first price at index Position ZERO.
So here we have the eight hundred seventy seven and now actually for our time stamps you can normalize
them the price of our index by dividing all values by the initial value and we can do this by having
here the sum for all rows and then we divide the sum for all rows by the very first element.
So let's have a look here.
So now our index is normalized to a value of 1.
And as it's more common to have a base value of 100 we actually multiply all values here with 100 and
we can do this with the Mayan method.
So let's sort this here and this is now actually our price weighted index.
So at the very first time stamp we have a base value of 100.
And then our index price changes depending on the performance of the constituent stocks.
So let's have a look at the very last time stamp.
So here at the end of two 18 we are already at a value of two hundred forty six and that's actually
a quite good multiplier.
Yes.
So we have a multiplier of two point four six.
And this only within five years.
So this is pretty good.
Now actually we can add our price weighted index to our norm data frame here on the right hand side.
So we create an additional column called price weighted index.
And we use exactly the code that we derived here.
So let's run this year and let's have a look.
So here we have our six constituents and our price weighted index.
Now we can also plot all six stocks in our price weighted index by using the plot method here on our
norm data frames for that.
So this and the price weighted index graph is actually here.
The dark blue graph so it's pretty hard to see here.
And as we can see here from the above from the uh non normalized stock prices by far the highest stock
price we have here for the Amazon stock.
So the Amazon stock has actually acquired a higher weight in our new index and maybe we can also see
this from a graph here.
So now we are only plotting.
The Amazon stock and our price weighted index.
And we can see here that they pretty much uh move together here.
So to say there is a lot of Amazon yeah our price weighted index.
And in contrast to that we could also plot the price weighted index.
And for example a lower weight stock.
So for example here the Coca-Cola stock that has only a little weight and our price weighted index.
So let's throw this here so we are plotting Coca-Cola and our price weighted index and we can see that
the correlation or the relationship between those two is uh fairly low actually.
And this is simply because there's only very little Coca-Cola in our index here.
So our index is actually dominated by the Amazon stock and we can also calculate the weights of the
constituents over time.
So let's again have a look at our stocks data frame.
The first five rows and we can see here at the very first timestamp that the Amazon price is much higher
than the Coca-Cola price.
So we would expect a much higher rate for the Amazon stock than for the Coca-Cola stock and our customized
to price index.
And we can actually calculate the weights of the constituents on each timestamp by actually dividing
here.
Each value by the sum of each row.
So we take uh the sum here for each row and then we divide all values in a row by the respective sum.
So we use see the tough method and we pass the rows to the axis perimeter.
So let's have a look and we can see at the very first timestamp.
So the weight of the Amazon stock is 45 percent and the weight of the Coca-Cola stock is only four point
seven percent.
And we can also have a look at the very end here.
So here we are at the end of 2018 and we can see here that the weight of the Amazon stock in our index
even increased to 68 percent.
And the weight of the Coca-Cola stock actually decreased to only two point two percent.
So this is kind of a weight data frame and we can also save this and the variable weights the price
weighted index and then we can also visualize the evolution of our weights over time by using the plot
method.
So let's have a look and we can see in blue the Amazon weight.
So starting at a weight of 45 percent in 2014 we end up at a rate of almost 70 percent in the year 2000
and 18.
And actually the weight of all other stocks is uh yeah fairly low here.
So our price weighted index is heavily influenced by the Amazon stock and uh the Amazon stock performance.
And this is actually one of the pitfalls of a price weighted index because stocks with the highest prices
have the highest rates and therefore the index has kind of a concentrated position in these stocks and
is actually poorly diversified and also a high stock price does not mean that the company is large in
a market capitalization sense.
So for example if there were only 100 stocks of the Amazon stock then Amazon would be a pretty small
company but with a huge position in our index and actually on the other hand side calculating and constructing
a price weighted indexes.
Pretty simple.
So we actually only need a two or three lines of code and very little data.
So we only need it actually the price data over time for our stocks.
So as a summary there are pros and cons for a price weighted index and in the next video we will create.
The equally weighted index.
So hope to see you there by.